<template>
  <div>
    <h2>会员信息修改</h2>
    <table>
      <tbody>
        
        <tr>
          <td>余额</td>
          <td>
            <input type="text" v-model="state.vprice" />
          </td>
        </tr>
        <tr>
          <td>积分</td>
          <td>
            <input type="text" v-model="state.targe" />
          </td>
        </tr>
        <tr>
          <td></td>
          <td>
            <input type="button" value="修改" @click="add" />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { reactive, toRefs, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();

let data = reactive({
  state: {
    vid: "",
    vprice: "",
    targe: "",
  },
});

let { state} = toRefs(data);

onMounted(() => {
  getData();
});

//反填
const getData = () => {
  let obj = {
    id: route.query.id,
  };

  axios({
    url: "/api/Vip/Fan",
    method: "get",
    params: obj,
  })
    .then((res) => {
      console.log(res);
      state.value = res.data.data;
    })
    .catch((err) => {
      console.log(err);
    });
};

const add = () => {
  let obj = {
    vid: state.value.vid,
    vprice: state.value.vprice,
    targe: state.value.targe,
  };
  axios({
    url: "/api/Vip/UpdateVip",
    method: "post",
    data: obj,
  })
    .then((res) => {
      console.log(res);
      if (res.data.data == 1) {
        alert("修改成功");
        router.push("/ShowVip");
      } else {
        alert("修改失败");
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped>
</style>

